//************************************************************
//    > File Name: add-binary.cpp
//    > Author: davis
//    > Mail:  
//    > Created Time: 2017年03月24日 14:11:23
//***********************************************************
//lintcode #408
#include<bits/stdc++.h>
using namespace std;
string addBinary(string& a, string& b) {
	string result;
	int result_length = max(a.length(), b.length()) ;
	cout<<"result_length:"<<result_length<<endl;
	int carry = 0;
	for (int i = 0; i < result_length; ++i) {
		int a_bit_i = i < a.length() ? a[a.length() - 1 - i] - '0' : 0;
		int b_bit_i = i < b.length() ? b[b.length() - 1 - i] - '0' : 0;
		int sum = carry + a_bit_i + b_bit_i;
		carry = sum / 2;
		sum %= 2;
		result.push_back('0' + sum);
	}
	if (carry) {
		result.push_back('0' + carry);
	}
	reverse(result.begin(), result.end());

	return result;
}
int main(){
	string a="11";
	string b="1";
	string c=addBinary(a,b);
	cout<<"a:"<<a<<"  "<<"b:"<<b<<"   "<<"c:"<<c<<endl;
}

